package com.lj.back.manage.scaffold.module.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lj.back.manage.scaffold.common.util.CommonUtil;
import com.lj.back.manage.scaffold.common.util.QueryWrapperUtil;
import com.lj.back.manage.scaffold.module.sys.DO.SysLogDO;
import com.lj.back.manage.scaffold.module.sys.DTO.SysLogDTO;
import com.lj.back.manage.scaffold.module.sys.DTO.SysLogPageQuery;
import com.lj.back.manage.scaffold.module.sys.dao.SysLogDao;
import com.lj.back.manage.scaffold.module.sys.service.SysLogService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 后台业务日志service实现类
 * @author lv
 * @version 1.0.0
 */
@Service
@AllArgsConstructor
public class SysLogServiceImpl implements SysLogService {

    private final SysLogDao sysLogDao;

    /**
     * 分页搜索查询后台业务日志列表
     * @param pageQuery
     * @return
     */
    @Override
    public IPage<SysLogDTO> listSysLogs(SysLogPageQuery pageQuery){
        QueryWrapper<SysLogDO> queryWrapper = QueryWrapperUtil.getPageQueryWrapper(SysLogDO.class, pageQuery,"user_name","operation","method","ip");
        LocalDateTime startTime = pageQuery.getStartTime();
        LocalDateTime endTime = pageQuery.getEndTime();
        queryWrapper.between(((null != startTime && null != endTime)),"create_time",startTime,endTime);
        queryWrapper.eq((pageQuery.getOperateType() != null),"operate_type",pageQuery.getOperateType());
        IPage<SysLogDO> sysLogPage = sysLogDao.selectPage(QueryWrapperUtil.getPage(pageQuery),queryWrapper);
        IPage<SysLogDTO> logDTOPage = CommonUtil.pageBeanConvert(sysLogPage, SysLogDTO.class);
        return logDTOPage;
    }
}
